﻿/* 
 * Copyright (C) 2014 Mehdi El Gueddari
 * http://mehdi.me
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

namespace EntityFramework.DbContextScope.Interfaces
{
	/// <summary>
	/// Factory for DbContext-derived classes that don't expose 
	/// a default constructor.
	/// </summary>
	/// <remarks>
	/// If your DbContext-derived classes have a default constructor, 
	/// you can ignore this factory. DbContextScope will take care of
	/// instanciating your DbContext class with Activator.CreateInstance() 
	/// when needed.
	/// 
	/// If your DbContext-derived classes don't expose a default constructor
	/// however, you must impement this interface and provide it to DbContextScope
	/// so that it can create instances of your DbContexts.
	/// 
	/// A typical situation where this would be needed is in the case of your DbContext-derived 
	/// class having a dependency on some other component in your application. For example, 
	/// some data in your database may be encrypted and you might want your DbContext-derived
	/// class to automatically decrypt this data on entity materialization. It would therefore 
	/// have a mandatory dependency on an IDataDecryptor component that knows how to do that. 
	/// In that case, you'll want to implement this interface and pass it to the DbContextScope
	/// you're creating so that DbContextScope is able to create your DbContext instances correctly. 
	/// </remarks>
	/// ///不公开的DbContext派生类的工厂
	///默认构造函数。
	///</摘要>
	///<备注>
	///如果DbContext派生类具有默认构造函数，
	///你可以忽略这个工厂。DbContextScope将负责
	///将DbContext类与Activator.CreateInstance激活器()
	///需要的时候。
	///
	///如果DbContext派生类不公开默认构造函数
	///但是，您必须弹劾这个接口并将其提供给DbContextScope
	///这样它就可以创建dbcontext的实例。
	///
	///需要这样做的典型情况是在DbContext派生的情况下
	///类依赖于应用程序中的其他组件。例如，
	///数据库中的某些数据可能已加密，您可能希望从DbContext派生
	///类在实体物化时自动解密此数据。因此
	///必须依赖于知道如何执行此操作的IDataDecryptor组件。
	///在这种情况下，您需要实现这个接口并将其传递给DbContextScope
	///您的创建是为了让DbContextScope能够正确地创建DbContext实例。

	public interface IDbContextFactory
	{
		 TDbContext CreateDbContext<TDbContext>(bool iReadOnly) where TDbContext : class, IDbContext; //, new();
	}
}
